import React from 'react';
import CommonList from '../../../components/CommonLists/list';
import services from '../../../services/api';
import { Tooltip } from 'antd';

class FieldList extends CommonList {
  constructor(props) {
    super(props);
    this.api = 'field';
    this.needOperateColumn = false;
    this.state = {
      applications: [],
      events: [],
    };
  }

  // 删除时的参数
  getDeleteParam = (record) => {
    return { field_id: record.field_id };
  };

  componentDidMount() {
    this.getEventCodeList(this.props.queryTableParams.app_id);
  }

  refreshTableFilter = (params) => {
    this.props.refreshTableFilter && this.props.refreshTableFilter(params);
    this.getEventCodeList(params.app_id);
    this.props.refreshTableFilter({ ...params, ...{ event_id: '' } });
  };

  getEventCodeList = (id) => {
    services.event.getEventCodeList({ app_id: id || '' }).then((res) => {
      if (res.code === 0) {
        this.setState({
          events: res.data,
        });
      }
    });
  };

  getColumn = () => {
    return [
      {
        title: '字段Code',
        key: 'field_code',
        dataIndex: 'field_code',
        ellipsis: true,
        width: 160,
        render: (text, record) => {
          return (
            <Tooltip title={text} placement='topLeft'>
              <div className='overflowtext' style={{ width: '100%' }}>
                {text}
              </div>
            </Tooltip>
          );
        },
      },
      {
        title: '字段名',
        key: 'field_name',
        dataIndex: 'field_name',
        ellipsis: true,
        width: 130,
        render: (text, record) => {
          return (
            <Tooltip title={text} placement='topLeft'>
              <div className='overflowtext' style={{ width: '100%' }}>
                {text}
              </div>
            </Tooltip>
          );
        },
      },
      {
        title: '类型',
        key: 'data_type',
        dataIndex: 'data_type',
        ellipsis: true,
      },
      {
        title: '长度',
        key: 'max_length',
        dataIndex: 'max_length',
        ellipsis: true,
      },
    ];
  };
}

export default FieldList;
